<?php

/**
 * @copyright 2012
 */

require_once("SqlUtils.php");
$type = $_GET["type"];
$name = $_GET["name"];
$img_id = $_GET["imgid"];

if(!$name)
{
    echo "name is empty";
    exit;
}

$newCategoryID = AddCategory($type,$name,$img_id);
if($newCategoryID == -1)
{
    echo "AddCategory error";
    exit;
}

 $doc = new DOMDocument();
  $doc->formatOutput = true;
  
  $r = $doc->createElement("categorys");
  $doc->appendChild($r);
  
  $s = $doc->createElement("category");
  $r->appendChild($s);
  
  $idNode = $doc->createElement( "id" );
  $idNode->appendChild($doc->createTextNode( $newCategoryID ));
  $s->appendChild($idNode);
  
  $nameNode = $doc->createElement( "name" );
  $nameNode->appendChild($doc->createTextNode( $name ));
  $s->appendChild($nameNode);
  
  $typeNode = $doc->createElement( "type" );
  $typeNode->appendChild($doc->createTextNode( $type ));
  $s->appendChild($typeNode);
  
  $imgidNode = $doc->createElement( "imgid" );
  $imgidNode->appendChild($doc->createTextNode( $img_id ));
  $s->appendChild($imgidNode);
  
  
  
  echo $doc->saveXML();


?>